package com.ce.pms.report.service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ce.pms.common.dao.ISysrefcodeDao;
import com.ce.pms.common.model.SysrefcodeDO;
import com.ce.pms.report.dao.IReportDao;
import com.ce.pms.report.queryvo.AlreadyChargeChargeTypeListQueryVO;
import com.ce.pms.report.vo.AlreadyBuildAndItemReportVO;
import com.ce.pms.report.vo.AlreadyChargeChargeTypeListReportVO;
import com.ce.report.entity.CEReportDataSet;
import com.ce.report.exception.CEReportException;
import com.ce.report.service.ICEReportDataSetService;
import com.ce.report.vo.ReportsQueryBaseVo;
import com.ce.util.BlankUtil;
import com.ce.util.DateUtil;

/**
 *
 * 功能描述：财务已收款收费方式明细表 Service
 * <p>版权所有：中企动力
 * <p>未经本公司许可，不得以任何方式复制或使用本程序任何部分
 *
 * @author 黄彦军
 * Created on 2008-11-3
 * Edit author:
 * Edit on:
 * 修改原因:
 */
public class AlreadyChargeChargeTypeListService implements ICEReportDataSetService {

	private IReportDao reportDao;
	private ISysrefcodeDao sysrefcodeDao;

	public CEReportDataSet getReportDataSet(ReportsQueryBaseVo arg) throws CEReportException {
		AlreadyChargeChargeTypeListQueryVO queryVO = (AlreadyChargeChargeTypeListQueryVO) arg;

		return new CEReportDataSet(getData(queryVO),getHeadInfo(queryVO));
	}

	/**
	 * 功能描述:获取列表数据  <br>
	 * @param queryVO
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-13  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<AlreadyChargeChargeTypeListReportVO> getData(AlreadyChargeChargeTypeListQueryVO queryVO){

		List<Object[]> temp = reportDao.getAlrChargeTypeList(queryVO);
		List<AlreadyChargeChargeTypeListReportVO> list = arrayToVo(temp);

		return list;
	}

	/**
	 * 功能描述:对象数组 转 VO 数组  <br>
	 * @param temp
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private List<AlreadyChargeChargeTypeListReportVO> arrayToVo(List<Object[]> temp){
		if(BlankUtil.isBlank(temp))
			return null;

		List<AlreadyChargeChargeTypeListReportVO> list = new ArrayList<AlreadyChargeChargeTypeListReportVO>();
		for (Object[] obj : temp) {
			AlreadyChargeChargeTypeListReportVO reportVO = new AlreadyChargeChargeTypeListReportVO();
			reportVO.setHouseNumber((String)obj[1]);	//房号
			reportVO.setUserName((String)obj[2]);		//客户名称
			reportVO.setAccounts((String)obj[3]);		//银行帐号
			reportVO.setComputeMonth((String)obj[4]);	//计费月份
			reportVO.setPayDate((Date)obj[5]);			//收费日期
			reportVO.setReceiptNO((String)obj[6]);		//单据号码

			String payTypeCode = (String)obj[7];//交费方式
			SysrefcodeDO sysrefcodeDO = sysrefcodeDao.getSysrefCodesByCode("FEE_BUSINESS_CODE_PAY_METHOD", payTypeCode);
			reportVO.setPayType(sysrefcodeDO.getName());

			reportVO.setActualPay((BigDecimal)obj[8]);	//实收金额

			list.add(reportVO);
		}

		return list;
	}

	/**
	 * 功能描述:获取头信息  <br>
	 * @return
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-13  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private Map<String, Object> getHeadInfo(AlreadyChargeChargeTypeListQueryVO queryVO) {
		Map<String, Object> map = new HashMap<String, Object>();
		String computeMonth = DateUtil.convertDateToStr(queryVO.getComputeMonth(), "yyyyMM");
		map.put("reportHeadStr", "计费月份:"+computeMonth);
		map.put("printDate", new Date());
		return map;
	}

	public void setReportDao(IReportDao reportDao) {
		this.reportDao = reportDao;
	}

	public void setSysrefcodeDao(ISysrefcodeDao sysrefcodeDao) {
		this.sysrefcodeDao = sysrefcodeDao;
	}

}
